﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AutoInsurance
{
    public partial class Calculation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //расчёт стоимости полиса
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                double expfactor;
                double agefactor;
                double powerfactor;
                double openfactor;
                double typefactor;
                double factor;
                int n1 = Convert.ToInt32(TextBox1.Text);
                if (n1 <= 3)
                {
                    expfactor = 1.5;
                }
                else
                {
                    expfactor = 1;
                }

                if (ListBox2.SelectedValue == "2")
                {
                    agefactor = 1.5;
                }
                else
                {
                    agefactor = 1.18;
                }
                int n3 = Convert.ToInt32(TextBox3.Text);
                if (n3 < 50)
                {
                    powerfactor = 1;
                }
                else if (n3 > 50 && n3 <= 70)
                {
                    powerfactor = 2;
                }
                else if (n3 > 70 && n3 <= 100)
                {
                    powerfactor = 3;
                }
                else if (n3 > 100 && n3 <= 120)
                {
                    powerfactor = 4;
                }
                else if (n3 > 120 && n3 <= 150)
                {
                    powerfactor = 5;
                }
                else if (n3 > 150)
                {
                    powerfactor = 6;
                }
                else
                {
                    powerfactor = 0;
                }
                if (RadioButtonList1.SelectedValue == "Без ограничений")
                {
                    openfactor = 1.3;
                }
                else
                {
                    openfactor = 1.14;
                }

                if (ListBox1.SelectedValue == "Мотоциклы и мотороллеры")
                {
                    typefactor = 1;
                }
                else if (ListBox1.SelectedValue == "Легковые автомобили")
                {
                    typefactor = 1.2;
                }
                else
                {
                    typefactor = 1.4;
                }

                if (RadioButtonList2.SelectedValue == "ОСАГО")
                {
                    factor = 450;
                }
                else
                {
                    factor = 620;
                }
                double sum = factor * typefactor * openfactor * powerfactor * agefactor * expfactor;
                string s1 = Convert.ToString(sum);
                TextBox4.Text = s1;
            }
            catch (FormatException)
            {
                TextBox4.Text = "Ошибка! Неверный формат данных";
            }
            catch (Exception ex)
            {
                Server.Transfer("Error.aspx?error=" + ex.Message);
            }


        }


    }
}